import threading
from utils import Timer

cnt = 50000000


def cuntdown():
    global cnt
    while cnt > 0:
        cnt -= 1


def single_thread():
    tick = Timer()
    cuntdown()
    print(f'single_thread 共耗时 {tick.tick()}s')


def multi_thread():
    tick = Timer()
    t1 = threading.Thread(target=cuntdown)
    t2 = threading.Thread(target=cuntdown)
    t1.start()
    t2.start()
    t1.join()
    t2.join()  # 等待此线程结束
    print(f'multi_thread 共耗时 {tick.tick()}s')


if __name__ == '__main__':
    # single_thread()
    multi_thread()
